package com.dao.impl;

import java.util.List;

import com.dao.OrgDao;

public class OrgDaoImpl extends UniversalDaoImpl implements OrgDao {

	@Override
	public List getListOrg() {//ifnull/isnull
		String sql = "select code,  isnull(parent_code,'') parent_code,name,url,target,isLeaf,enabled from Org where enabled=1 order by code";
		logger.info(sql);
		return queryForList(sql);
	}

	@Override
	public List getListOrgTreeByCode(String code) {
		String sql;
		if (code == null || code.equals("null") || code.equals(""))
			sql = "select id,isnull(parent_code,'') parentid,leaf,text from (select code id,parent_code,'['+code+'] '+name text,isLeaf leaf from Org where parent_code is null or parent_code='') t order by id";
		else
			sql = "select id,isnull(parent_code,'') parentid,leaf,text from (select code id,parent_code,'['+code+'] '+name text,isLeaf leaf from Org where parent_code='"
					+ code + "' ) t order by id";
		logger.info(sql);
		return queryForList(sql);
	}

}
